﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using BIExtAuth.Model;
using BIExtAuth.BLL;
using BIExtAuth.Common;

namespace BIExtAuth.Web.Admin
{
    public partial class ChangePwd : System.Web.UI.Page
    {
        public bool state = false;
        private UserBLL userBLL = new UserBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["userID"]))
            {

            }
        }

        protected void BtnChangePwd_Click(object sender, EventArgs e)
        {
            if (txtPwd.Text != txtPwdAgain.Text)
            {
                msg.Text = "新密码和再确认密码不一致！";
            }
            else
            {
                BIUser user = this.userBLL.GetUserByUserID(this.txtUserID.Text.Trim());
                if (user == null)
                {
                    msg.Text = "用户ID不存在！";
                }
                else
                {
                    if (SecurityEncrypt.DesDecrypt(user.UserPwd) == this.txtOldPwd.Text)
                    {
                        user.UserPwd = SecurityEncrypt.DesEncrypt(this.txtPwd.Text);
                        int ret = this.userBLL.ChangePwd(user);
                        if (ret > 0)
                        {
                            msg.Text = "密码修改成功！";
                        }
                        else
                        {
                            msg.Text = "密码修改失败！";
                        }
                    }
                    else
                    {
                        msg.Text = "原密码错误！";
                    }
                }
            }
        }
    }
}